package com.example.mywood;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import bean.ContentDataBean;
import myapp.MyApp;
import util.MyLog;
import util.SystemStatusManager;

public class MessageListActivity extends BaseActivity {


    private LinearLayout ll_reback;
    private TextView tv_calll_service;
    private SharedPreferences sharedPreferences;
    private String textData;
    private WebView webview;
    private MyApp myapp;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_messagelist);
        myapp = (MyApp) getApplicationContext();
        setTranslucentStatus();
        sharedPreferences = getSharedPreferences("userInfo", Context.MODE_PRIVATE);
        String token = sharedPreferences.getString("token", "");
        String apptype = sharedPreferences.getString("apptype", "0");
        textData = sharedPreferences.getString("textData", "");
        initView();
        initLin();


    }


    private void initView() {
        ll_reback = findViewById(R.id.ll_reback);
        webview = findViewById(R.id.webview);
        // 设置WebView的客户端
        webview.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                return false;// 返回false
            }
        });
        WebSettings webSettings = webview.getSettings();
        // 让WebView能够执行javaScript
        webSettings.setJavaScriptEnabled(true);
        // 让JavaScript可以自动打开windows
        webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
        // 设置缓存
        webSettings.setAppCacheEnabled(true);
        // 设置缓存模式,一共有四种模式
        webSettings.setCacheMode(webSettings.LOAD_CACHE_ELSE_NETWORK);
        // 设置缓存路径
//        webSettings.setAppCachePath("");
        // 支持缩放(适配到当前屏幕)
        webSettings.setSupportZoom(true);
        // 将图片调整到合适的大小
        webSettings.setUseWideViewPort(true);
        // 支持内容重新布局,一共有四种方式
        // 默认的是NARROW_COLUMNS
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        // 设置可以被显示的屏幕控制
        webSettings.setDisplayZoomControls(true);
        // 设置默认字体大小
        webSettings.setDefaultFontSize(12);


        MyLog.e("77777777777",myapp.getWebConfig()+"/addons/kefu/index/mobile");
//        webview.loadUrl(myapp.getWebConfig()+"/addons/kefu/index/mobile");
        webview.loadUrl("https://www.woodwoodslab.com/addons/kefu/index/mobile");
        tv_calll_service = findViewById(R.id.tv_calll_service);
        TextView tv_title = findViewById(R.id.tv_title);
        ContentDataBean.DataBean textContent = new Gson().fromJson(textData, new TypeToken<ContentDataBean.DataBean>() {}.getType());
        if (textContent != null){
            tv_title.setText(textContent.getMessage_list());

        }
    }


    private void initLin() {
        ll_reback.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });
        tv_calll_service.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
//                if(ChatClient.getInstance().isLoggedInBefore()){
//                    //已经登录，可以直接进入会话界面  //获取地址：kefu.easemob.com，“管理员模式 > 渠道管理 > 手机APP”页面的关联的“IM服务号”
//                    Intent intent = new IntentBuilder(MessageListActivity.this).setServiceIMNumber("kefuchannelimid_398963").build();
//                    startActivity(intent);
//                }else{
//                    //未登录，需要登录后，再进入会话界面
//                }
            }
        });
    }
    /**
     * 设置状态栏背景状态
     */
    public  void setTranslucentStatus()
    {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
        {
            Window win =  getWindow();
            WindowManager.LayoutParams winParams = win.getAttributes();
            final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
            winParams.flags |= bits;
            win.setAttributes(winParams);
        }
        SystemStatusManager tintManager = new SystemStatusManager(this);
        tintManager.setStatusBarTintEnabled(true);
        tintManager.setStatusBarTintResource(0);//状态栏无背景
    }

}
